package com.skyblue.statemachine.persist;

import com.skyblue.statemachine.config.Order;
import com.skyblue.statemachine.config.OrderEvents;
import com.skyblue.statemachine.config.OrderStates;
import org.springframework.statemachine.StateMachineContext;
import org.springframework.statemachine.StateMachinePersist;
import org.springframework.statemachine.support.DefaultStateMachineContext;
import org.springframework.stereotype.Component;

@Component
public class OrderStateMachinePersist implements StateMachinePersist<OrderStates, OrderEvents, Order> {

    @Override
    public void write(StateMachineContext<OrderStates, OrderEvents> context, Order order) throws Exception {
        //这里不做任何持久化工作
    }

    @Override
    public StateMachineContext<OrderStates, OrderEvents> read(Order order) throws Exception {

        return new DefaultStateMachineContext<>(OrderStates.valueOf(order.getState()), null, null, null, null, "orderMachine");
    }

}